home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / QUOTAOPS.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  141 lines

  1. /*
  2.  * Definitions for diskquota-operations. When diskquota is configured these
  3.  * macros expand to the right source-code.
  4.  *
  5.  * Author:  Marco van Wieringen <mvw@planets.elm.net>
  6.  *
  7.  * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
  8.  *
  9.  */
  10. #ifndef _LINUX_QUOTAOPS_
  11. #define _LINUX_QUOTAOPS_
  12.  
  13. #include <linux/config.h>
  14.  
  15. #if defined(CONFIG_QUOTA)
  16.  
  17. /*
  18.  * declaration of quota_function calls in kernel.
  19.  */
  20. extern void dquot_initialize(struct inode *inode, short type);
  21. extern void dquot_drop(struct inode *inode);
  22. extern void invalidate_dquots(kdev_t dev, short type);
  23. extern int  quota_off(kdev_t dev, short type);
  24. extern int  sync_dquots(kdev_t dev, short type);
  25.  
  26. extern int  dquot_alloc_block(const struct inode *inode, unsigned long number,
  27.                               uid_t initiator, char warn);
  28. extern int  dquot_alloc_inode(const struct inode *inode, unsigned long number,
  29.                               uid_t initiator);
  30.  
  31. extern void dquot_free_block(const struct inode *inode, unsigned long number);
  32. extern void dquot_free_inode(const struct inode *inode, unsigned long number);
  33.  
  34. extern int  dquot_transfer(struct inode *inode, struct iattr *iattr,
  35.                            char direction, uid_t initiator);
  36.  
  37. /*
  38.  * Operations supported for diskquotas.
  39.  */
  40. extern __inline__ void DQUOT_INIT(struct inode *inode)
  41. {
  42.     if (inode->i_sb && inode->i_sb->dq_op)
  43.         inode->i_sb->dq_op->initialize(inode, -1);
  44. }
  45.  
  46. extern __inline__ void DQUOT_DROP(struct inode *inode)
  47. {
  48.     if (IS_QUOTAINIT(inode)) {
  49.         if (inode->i_sb && inode->i_sb->dq_op)
  50.             inode->i_sb->dq_op->drop(inode);
  51.     }
  52. }
  53.  
  54. extern __inline__ int DQUOT_PREALLOC_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
  55. {
  56.     if (sb->dq_op) {
  57.         if (sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize),
  58.                        current->fsuid, 0) == NO_QUOTA)
  59.             return 1;
  60.     }
  61.     return 0;
  62. }
  63.  
  64. extern __inline__ int DQUOT_ALLOC_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
  65. {
  66.     if (sb->dq_op) {
  67.         if (sb->dq_op->alloc_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize),
  68.                        current->fsuid, 1) == NO_QUOTA)
  69.             return 1;
  70.     }
  71.     return 0;
  72. }
  73.  
  74. extern __inline__ int DQUOT_ALLOC_INODE(struct super_block *sb, struct inode *inode)
  75. {
  76.     if (sb->dq_op) {
  77.         sb->dq_op->initialize (inode, -1);
  78.         if (sb->dq_op->alloc_inode (inode, 1, current->fsuid))
  79.             return 1;
  80.     }
  81.     inode->i_flags |= S_QUOTA;
  82.     return 0;
  83. }
  84.  
  85. extern __inline__ void DQUOT_FREE_BLOCK(struct super_block *sb, const struct inode *inode, int nr)
  86. {
  87.     if (sb->dq_op)
  88.         sb->dq_op->free_block(inode, fs_to_dq_blocks(nr, sb->s_blocksize));
  89. }
  90.  
  91. extern __inline__ void DQUOT_FREE_INODE(struct super_block *sb, struct inode *inode)
  92. {
  93.     if (sb->dq_op)
  94.         sb->dq_op->free_inode(inode, 1);
  95. }
  96.  
  97. extern __inline__ int DQUOT_TRANSFER(struct dentry *dentry, struct iattr *iattr)
  98. {
  99.     int error = -EDQUOT;
  100.  
  101.     if (dentry->d_inode->i_sb->dq_op) {
  102.         if (IS_QUOTAINIT(dentry->d_inode) == 0)
  103.             dentry->d_inode->i_sb->dq_op->initialize(dentry->d_inode, -1);
  104.         if (dentry->d_inode->i_sb->dq_op->transfer(dentry->d_inode, iattr, 0, current->fsuid))
  105.             goto out;
  106.         error = notify_change(dentry, iattr);
  107.         if (error)
  108.             dentry->d_inode->i_sb->dq_op->transfer(dentry->d_inode, iattr, 1, current->fsuid);
  109.     } else {
  110.         error = notify_change(dentry, iattr);
  111.     }
  112. out:
  113.     return error;
  114. }
  115.  
  116. #define DQUOT_SYNC(dev)    sync_dquots(dev, -1)
  117. #define DQUOT_OFF(dev)    quota_off(dev, -1)
  118.  
  119. #else
  120.  
  121. /*
  122.  * NO-OP when quota not configured.
  123.  */
  124. #define DQUOT_INIT(inode)            do { } while(0)
  125. #define DQUOT_DROP(inode)            do { } while(0)
  126. #define DQUOT_PREALLOC_BLOCK(sb, inode, nr)    (0)
  127. #define DQUOT_ALLOC_BLOCK(sb, inode, nr)    (0)
  128. #define DQUOT_ALLOC_INODE(sb, inode)        (0)
  129. #define DQUOT_FREE_BLOCK(sb, inode, nr)        do { } while(0)
  130. #define DQUOT_FREE_INODE(sb, inode)        do { } while(0)
  131. #define DQUOT_SYNC(dev)                do { } while(0)
  132. #define DQUOT_OFF(dev)                do { } while(0)
  133.  
  134. /*
  135.  * Special case expands to a simple notify_change.
  136.  */
  137. #define DQUOT_TRANSFER(dentry, iattr) notify_change(dentry, iattr)
  138.  
  139. #endif /* CONFIG_QUOTA */
  140. #endif /* _LINUX_QUOTAOPS_ */
  141.